<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <#include "../common/header.ftl">
    <script type="text/javascript" src="/js/plugins/chosen/chosen.jquery.js"></script>
    <link rel="stylesheet" href="/js/plugins/chosen/component-chosen.css" type="text/css" />



    <script type="text/javascript">

    	$(function(){
            $('#pagination').twbsPagination({
                totalPages:${result.pages}||1,
                startPage:${result.pageNum},
                visiblePages:${result.pageSize},
                first:"首页",
                prev:"上页",
                next:"下页",
                last:"尾页",
                onPageClick:function(event, page){
                    //讲当前页设置page值
                    $("#currentPage").val(page);
                    //表单提交gjk,mb/.
                    $("#searchForm").submit();
                }
            });

            //修改按钮
            $(".editBtn").click(function(){
                $("#editForm")[0].reset();
                var json = $(this).data("json");

                console.log(json);

                $("#strategyId").val(json.id);
                $("#title").val(json.title);
                $("#subTitle").val(json.subTitle);
                $("#state").val(json.state);

                $("#coverImg").attr('src',json.coverUrl);
                $("#coverUrl").val(json.coverUrl);

                //回显地区,用普通方式回显
                $("#place option[value="+json.placeId+"]").prop('selected',true)
                //让插件执行更新操作
                $("#place").trigger("chosen:updated")

                $("#strategyModal").modal('show');
            })

            //地区回显的异步请求
            $.get('/region/listAll.do', function (data) {
                var html = "<option></option>";

                //循环取出data中的数据
                $.each(data, function (index, ele) {
                    html += "<option value='" + ele.id + "'>" + ele.name + "</option>"

                })
                $("#place").html(html)

                //初始化组件
                $("#place").chosen({
                    placeholder_text_single:"请选择地点",
                    disable_search_threshold: 5,//大于10条就显示搜索框
                    no_results_text: "无相关地区!"//搜索时找不到的提示
                })

            })

            //保存按钮
            $("#saveBtn").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        $.messager.confirm("温馨提示","操作成功!",function () {
                            window.location.reload();
                        })
                    }else{
                        $.messager.alert("错误信息",data.msg);
                    }
                })
            })

            //新增按钮
            $(".addBtn").click(function () {
                $("#editForm")[0].reset()
                $("#strategyModal").modal('show')
            })

    	})
    </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
<#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
        <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">平台用户管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategy/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}" placeholder="请输入名字">
                </div>

                <button id="btn_query" class="btn btn-default">查询</button>
                <button type="button" class="btn btn-success addBtn">新增</button>

            </form>

            <table class="table table-striped table-hover" >
                <thead>
                    <tr>

                        <th>编号</th>
                        <th>封面</th>
                        <th>标题</th>
                        <th>副标题</th>
                        <th>所属地区</th>
                        <th>状态</th>
                    </tr>
                </thead>
                <#list result.list as entity>
                   <tr>
                       <td>${entity_index+1}</td>
                       <td><img src="${entity.coverUrl}" width="30px"/> </td>
                       <td>${entity.title}</td>
                       <td>${entity.subTitle}</td>
                       <td>${(entity.place.name)!}</td>
                       <td>
                           <#if entity.state==-1>
                               禁用
                           <#elseif entity.state==0>
                               普通
                           <#elseif entity.state==1>
                               推荐
                           </#if>
                       </td>
                       <td><a href="javascript:void(0);" class="editBtn" data-json='${entity.jsonString}'>修改</a></td>
                   </tr>
                </#list>
            </table>
            <div style="text-align: center;">
                <ul id="pagination" class="pagination"></ul>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="strategyModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">新增/修改</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategy/saveOrUpdate.do" method="post" id="editForm"  enctype="multipart/form-data" >
                    <input type="hidden"  id="strategyId" name="id">
                    <div class="form-group" >
                        <label for="name" class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title"  >
                        </div>
                    </div>
                    <div class="form-group" >
                        <label for="name" class="col-sm-4 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="subTitle" name="subTitle"  >
                        </div>
                    </div>
                    <div class="form-group" >
                        <label for="name" class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverImg" width="50%" />
                            <input type="hidden" class="form-control" id="coverUrl" name="coverUrl"  >
                            <input type="file" class="form-control" id="coverFile" name="file"  >
                        </div>
                    </div>
                    <div class="form-group" >
                        <label for="name" class="col-sm-4 control-label">所属地区：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="place" name="place.id"  >
                            </select>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label for="name" class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="state" id="state">
                                <option value="-1">禁用</option>
                                <option value="0" selected>普通</option>
                                <option value="1">推荐</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success" id="saveBtn">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

</body>
</html>